
#include "registry_loader.h"

#include <fstream>

#include "registry_error.h"
#include "registry_storage.h"



void registry_loader::load(registry_storage& container, const std::string& filename)
{
	std::ifstream ifs(filename.c_str(), std::ios::in);

	if (!ifs.is_open())
		throw registry_error("unable to open file");

	std::string line;
	while(ifs.good() )
	{
		std::getline(ifs, line);

		if(line.empty())
			break;

		std::string::size_type comma_position = line.find(',');

		std::string key = line.substr(0, comma_position);
		std::string value = line.substr(comma_position + 1);

		container.add(key, value);
	}

	ifs.close();
}
